import request from './request'
import {baseUrl} from './const'


/**
 * 通用api接口
 */
export const api = {
    Login: '/admin/login',
    Logout: '/admin/logout',
    GetMenus: '/menu/queryRoleMenus',   // 根据角色获取菜单路由
    AdminEntities: '/admin/queryList', // 查询电站管理员列表
    UserEntities: '/user/queryList',
    GetUserList: '/user/getUserList',
    SaveUser: '/user/saveSingle',
    RoleEntities: '/role/queryList',
    MenuEntities: '/menu/queryList',
    SaveMenu: '/menu/saveSingle',       // 新增菜单路由
    GetMenuList: '/menu/getList',       // 获取所有菜单路由，组装成树
    SaveRoleMenu: '/roleMenu/saveRoleMenu',     // 保存角色菜单
    GetRoleList: '/role/getRoleList',
    AreaEntities: '/area/queryList',
    SaveStation: '/station/saveSingle',
    UploadStationImg: '/station/uploadFile',
    StationSingle: '/station/querySingle',
    UpdateStation: '/station/updateSingle',
    StationEntities: '/station/queryList',
    GetStationList: '/station/getList',
    // 充电桩
    PileEntities: '/pile/queryList',
    GetPileList: '/pile/getList',
    SavePile: '/pile/saveSingle',
    UpdatePile: '/pile/updateSingle',
    PileSingle: '/pile/querySingle',
    // 充电枪
    SpearEntities: '/spear/queryList',
    GetSpearList: '/spear/getList',
    SaveSpear: '/spear/saveSingle',
    UpdateSpear: '/spear/updateSingle',
    SpearSingle: '/spear/querySingle',
    SaveMerchant: '/merchant/saveSingle',
    MerchantEntities: '/merchant/queryList',
    // 计费规则
    RulesEntities: '/rules/queryList',
    GetRules: '/rules/getList',
    SaveRules: '/rules/saveSingle',
    UpdateRules: '/rules/updateSingle',
    RulesSingle: '/rules/querySingle',
    // 分时段计费规则
    RulesUnitEntities: '/rulesUnit/queryList',
    SaveRulesUnit: '/rulesUnit/saveSingle',
    UpdateRulesUnit: '/rulesUnit/updateSingle',
    RulesUnitSingle: '/rulesUnit/querySingle',
    // 资金流水
    TransactionEntities: '/transaction/queryList',
    // 会员记录
    MemberEntities: '/member/queryList',
    SaveMember: '/member/saveSingle',
    UpdateMember: '/member/updateSingle',
    UploadMemberImg: '/member/uploadFile',
}

export function post( url, param ) {
    return request.postToken ( baseUrl + url, param )
}

// 上传
export function uploadFile( url, parameter ) {
    const dealData = new FormData ()
    dealData.append ( "token", window.sessionStorage.getItem ( 'token' ) );
    for ( let key in parameter ) {
        dealData.append ( key, parameter[key] )
    }
    return request.upload ( baseUrl + url, parameter )
}
